﻿define([
    'require',
    'angular',
    'underscore'
], function (require, angular, _) {
    return function ($scope, $routeParams, $http, RuleSerivce,$dataSourceManager,$timeout,Resource,$compile,$rootScope, GillionMsg) {

        var remoteResource = Resource("/grule-manager/remote/:id", {
            id: "@id"
        });

        $timeout(function(){
            var params={};
            params.projectId =$routeParams.projectId;
            $dataSourceManager.dataSources["RemoteSource"].params = params;
            $dataSourceManager.dataSources["RemoteSource"].doRequestData();
        },100);

        $scope.addRemote=function(){
            $scope.dlg = GillionMsg.showUrl({
                title: '新建远程服务',
                url: '/html2/component/remote/remoteManager',
                data:{projectId:$routeParams.projectId,projectCode:$scope.currProjcet.projectCode},
                height:400,
                width:700,
                onClose: function(){
                    $scope.submit();
                }
            });
        };

        $scope.removeRemote=function(row){
            GillionMsg.confirm("提示信息","是否确定删除？",function(r){
                if(r){
                    remoteResource.delete({
                        id:  row.id
                    }, function () {
                        var param = {};
                        param.projectId=row.projectId;
                        $dataSourceManager.dataSources["RemoteSource"].params = param;
                        $dataSourceManager.dataSources["RemoteSource"].doRequestData();
                    });
                }
            })
        }

        $scope.submit= function(){
            var param={};
            param.projectId = $routeParams.projectId;
            param.remoteName = document.getElementById("remoteName").value;
            param.remoteCode = document.getElementById("remoteCode").value;
            $dataSourceManager.dataSources["RemoteSource"].params = param;
            $dataSourceManager.dataSources["RemoteSource"].doRequestData();
        }


        $scope.editRemote=function (row){
            $scope.dlg = GillionMsg.showUrl({
                title: '修改远程服务',
                url: '/html2/component/remote/remoteManager',
                data:row,
                height:400,
                width:700,
                onClose: function(){
                    var param = {};
                    param.projectId = $routeParams.projectId;
                    param.remoteName = $scope.remoteName;
                    param.remoteCode = $scope.remoteCode;
                    $dataSourceManager.dataSources["RemoteSource"].params = param;
                    $dataSourceManager.dataSources["RemoteSource"].doRequestData();
                }
            });
        };

    };
});